-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Doc] Add 'static
and Send
constraints explanations to thread::spawn
#41980
Conversation
'static
and Send
constraints explanations to thread::spawn
'static
and Send
constraints explanations to thread::spawn
src/libstd/thread/mod.rs
Outdated
/// - The `'static` constraint means that the closure and its return value | ||
/// must have a lifetime of the whole program execution. The reason for this | ||
/// is that threads can `detach` and outlive the lifetime they have been | ||
/// created in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread being able to outlive the scope it has been created in (i.e. detaching
) is only an explanation for why closure itself is 'static
, and not its return value. The return value has the 'static
bound because the return value outlives the thread it is returned from; this is true regardless of whether the thread gets detached or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actually linked.
The value a thread returns must outlive the closure, but the fact that the thread can detach implies that the closure must be 'static
, since the value must live at least as long as the closure it must then also be 'static
r? @rust-lang/docs |
Tidy errors:
|
Damn, that is valid markdown though... |
@steveklabnik This looks read for review. |
@bors: r+ rollup thanks! |
📌 Commit 770bd57 has been approved by |
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
Part of #29378.
Explains why the constraints on the closure and its return value are
'static
andSend
.Allows to tick of
thread::spawn
from the list of things to document in thethread
module.r? @steveklabnik